<?php
	defined('_JEXEC') or die('Restricted access');
	require_once(CUTEENGINE_BASE_ACTION_PATH."base_action_class.php");
    require_once(CUTEENGINE_BASE_STEP_PATH."base_step_class.php");
	//
    // t_action_execute_field_method
    //
	class t_action_execute_field_method extends t_base_action
	{
        // property declaration
		// protected        
		const language_position_last = 1;
		

		// property declaration
		// public
		// P
        const proper_properties_position_per_event_type = 0;
        const proper_properties_position_per_event_name = 1;
        const proper_properties_position_per_method_name = 2;
        const proper_properties_position_last = 3;
        // R
        const required_fields_count = 1;
		//
		const step_start = 0;
        // method declaration
    	// protected
        // G
		static function get_help_proper_property($a_index)
		{
			$local_return = 'NO HELP AVAILABLE';
			/*switch ($a_index) 
            {
                case self::proper_properties_position_:
					$local_return = '';
				break;                
			}*/
			return $local_return;
		}
        static function get_default_proper_property($a_index)
		{
			$local_return = '';
			//echo "a_index: $a_index<br>";
			/*switch ($a_index) 
            {
				case self::proper_properties_position_per_:
					$local_return = '';
				break;				
			}*/
			return $local_return;
		}		
        protected function get_proper_properties_position_last()
        {
            return self::proper_properties_position_last;
        }
		protected function get_required_fields_count()
        {
            return self::required_fields_count;
        }
        

		// I
        protected function initialize_action()
        {		

			if (! $this->initialized)
			{
                parent::initialize_action();
                //$this->initialized = true;

			}
			return $this->initialized;
		}		
        protected function initialize_step_execution()
        {		

			$local_step = $this->steps_list[$this->current_step_index];
			//print_r($local_step);
			$local_index = $this->current_step_index;			
			$local_step->initialize();
			//echo "$local_index local_step->name:".$local_step->name."<br>";
			$this->custom_execute_step($local_step);                                            
		}	
        protected function custom_execute_step($a_step)        
        {
            $local_field = $a_step->field;

			$local_main_tag = $local_field->get_executor_tag();
		   // print_r($local_main_tag);
		    //echo "local_main_tag: ".$local_main_tag->name."<br>";
			$local_class = get_class($a_step);
			//echo "local_class:$local_class<br>";
			$local_field_class = get_class($local_field);
			switch ($local_class) 
			{
				/*********** t_step_set_ce_field_event ***********/
				case t_step_set_ce_field_event:
					$local_field->add_event($this->get_event_type(), $this->get_event_name(),
						"var local_parent = ".t_cuteengine::javascript_instance_name."['".$local_field->name."'];
	if (!local_argoument)
		var local_argoument = local_parent.prepare_childs_values_to_send('".$local_main_tag->name."');
	else	
		local_argoument = local_parent.prepare_childs_values_to_send('".$local_main_tag->name."',local_argoument);
	if (local_argoument === false)
		return false;
	".$this->get_content_loader_code('',false,true));
				break;		
			}
        }
        // method declaration
    	// public
        public function __construct($a_parent_component,$a_parent_part,$a_common_properties_str, $a_proper_properties_str) 
		{
            //echo "a_common_properties_str:$a_common_properties_str<br>";
			parent::__construct($a_parent_component,$a_parent_part,$a_common_properties_str, $a_proper_properties_str);
           // echo "count:".count($this->fields_list);
			// steps
            //print_r($this->fields_list);
			$this->steps_list[t_base_action::step_start] = t_base_step::create_step_from_string('|t_step_set_ce_field_event|'.$this->get_action_name().'_get|'.
              $this->fields_list[t_base_action::step_start].'|'); 
			
		}
        
		public function do_action_from_ajax()
        {
			$local_parameter = parent::do_action_from_ajax();
			//print_r($this->steps_list[t_base_action::step_start]);
			$local_step = $this->steps_list[t_base_action::step_start];
            $local_field = $local_step->field;
			//echo "local_step->name:".$local_step->name."<br>";
			$local_method_name = $this->get_method_name();
			$local_class = get_class($local_field);
			//echo "local_field->name:".$local_field->name." - local_class: $local_class - local_method_name: $local_method_name<br>"; 
			$local_result = new t_content_loader_result;
			$local_field->$local_method_name($local_parameter,$local_result);
			//echo $local_result->get_json_string();
            $this->execute_child_ations($local_result);						
				
        }        
		// G		
 
		public function get_event_type()
        {	
			return $this->proper_properties_array[self::proper_properties_position_per_event_type];
			
		} 
        
		public function get_language_position_last()
        {
            return self::language_position_last;
        }	
		public function get_event_name()
        {	
			return $this->proper_properties_array[self::proper_properties_position_per_event_name];
			
		}		
		public function get_method_name()
        {	
			return $this->proper_properties_array[self::proper_properties_position_per_method_name];
			
		}
    }
?>    